home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / graphic.zip / LINE.C < prev    next >
Text File  |  1991-12-24  |  1KB  |  50 lines

  1. /**********************************************************************
  2. LINE
  3. Description - draws a line from two points
  4. **********************************************************************
  5. Function - line(x0,y0,x1,y1) coord for point 0 and point 1
  6. Input - see above
  7. Output - to the screen
  8. #includes - none
  9. #defines  - none
  10. Routines Called - plotxy
  11. Notes - BYTE august 1981, pp414-16; digital differential analyzer DDA
  12. **********************************************************************/
  13. line(x0,y0,x1,y1)
  14. int x0,y0,x1,y1;
  15. {
  16.   plotxy(x0,y0); /* print the first point */
  17.   plotxy(x1,y1); /* print the end point */
  18.   /* initialize the remaining variables and set the whole thing up */
  19.   int d1,d2,d3,s1,s2,a1,a2,n1;
  20.   d1=x1-x0;
  21.   d2=y1-y0;
  22.   s1=0;
  23.   s2=1;
  24.   a1=1;
  25.   a2=0;
  26.   if (d1<0){a1=-1;d1=-d1;}
  27.   if (d2<0){d2=-d2;s2=-1;}
  28.   if (d1<d2){ n1=d1;
  29.               d1=d2;
  30.               d2=n1;
  31.               s1=a1;
  32.               a1=0;
  33.               a2=s2;
  34.               s2=0;  }
  35.   d3=d1/2;
  36.   n1=1;
  37.  
  38.   /* heres where the work gets done */
  39.   do{
  40.       x0=x0+a1;
  41.       y0=y0+a2;
  42.       d3=d3+d2;
  43.       n1=n1+1;
  44.       if(d3>d1){d3=d3-d1; x0=x0+s1; y0=y0+s2;}
  45.       plotxy(x0,y0);
  46.     }while(n1<=d1);
  47.   return;
  48. }
  49. /******************** end of function ********************************/
  50.